//this is a dynamic
#include <iostream>
using namespace std;
const int MAX=10000;
int min(int x,int y)
{
	return x<y?x:y;
}
void  DynamicTable(int **M,int y,int *v,int number)
{
		int i=0,j=0;

		for(i=0;i<=number;i++)
		{
			for(j=0;j<=y;j++)
			{
				M[i][j]=MAX;
			//	cout<<M[i][j];
			}
		}
		for(i=1;i<=number;i++)
		{
			for(j=1;j<=y;j++)
			{
				if(i==1)
				{
					if(v[i]==j)
						M[i][j]=1;
				}
				else
				{
					if(j-v[i]<0)
						M[i][j]=M[i-1][j];
					else
						M[i][j]=min(M[i-1][j],M[i-1][j-v[i]]+1);
				}
			}
		}
			//return 0;
}
bool PrintResult(int **M,int y,int number,int *v)
{
	int k,min=0,i=0,j,*Result;
	Result=new int[number];
	for(k=1;k<=number;k++)
	{
		if(M[k][y]<M[min][y])
			min=k;
	}
	if(min==0)
		return false;
	i=min,j=y,k=0;
	//cout<<min<<endl;
	do
	{
		while(M[i][j]==M[i-1][j])
			i--;
		Result[k++]=v[i];
		//if(j-v[])
		j-=v[i];
		i--;
		
	}while(i!=0);
	cout<<"RESULT IS"<<endl;
	for(i=k-1;i>=0;i--)
		cout<<Result[i]<<endl;
	return true;

}
void main()
{
	int y=12,k=0,min=MAX;
	int v[5]={0,1,5,6,11};
	int number=4;
	int **M=new int *[number+1];
		for(k=0;k<=number;k++)
		{
			M[k]=new int[y+1];
		}
	DynamicTable(M,12,v,4);
	PrintResult(M,y,number,v);
		 
}